<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class School extends Model
{

    use SoftDeletes;

    public $table = 'schools';

    public $fillable = [
        'name'
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function student()
    {
        return $this->hasMany(Student::class, 'school_id', 'id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function orders()
    {
        return $this->hasMany(Order::class, 'school_id', 'id');
    }


    public function courses(){
        return $this->belongsToMany(Course::class,'school_has_tests_courses','school_id','lesson_test_id')
            ->where('school_has_tests_courses.product_type','lesson');
    }

    /**
     * @param $id
     * @return mixed
     */
    public static function getName($id)
    {
        $model = self::query()->where('id', $id)->first();
        return $model->name;
    }

}
